package com.shell.governor.user.service.impl;

import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.governor.user.dao.PubUserExtraDao;
import com.shell.governor.user.po.PubUserExtra;
import com.shell.governor.user.service.PubUserExtraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PubUserExtraServiceImpl extends PersistentServiceImpl<PubUserExtra> implements PubUserExtraService {
	@Autowired
	private PubUserExtraDao pubUserExtraDao;

	public String getInviteCode(String userId, String entId) {
		PubUserExtra pubUserExtra = new PubUserExtra();
		pubUserExtra.setEntId(entId);
		pubUserExtra.setUserId(userId);
		pubUserExtra = (PubUserExtra) selectOne(pubUserExtra);
		if (pubUserExtra == null) {
			return "";
		}
		return pubUserExtra.getInviteCode();
	}

	public void updateUserStateForEnt(String entId, String userState) {
		String originalState;
		if ("F".equals(userState)) {
			originalState = "E";
		} else {
			originalState = "F";
		}
		this.pubUserExtraDao.updateUserStateForEnt(entId, userState, originalState);
	}
}
